﻿using System.Collections.Generic;
using SimpleOrmCFPC.Core.Query.Where;

namespace SimpleOrmCFPC.Core.Query.Requests
{
    public static class SQLRequestExtensions
    {
        public static void AddJoin(this SQLRequest request, string propertyName, string joinTable, string joinTableId)
        {
            string table = request.tableNames[0];
            request.tableNames.Add(table);
            request._where.Add(new OperatorWhereElement("=",
                                                        new SimpleWhereElement(
                                                            string.Format("{0}.{1}", table, propertyName),
                                                            new List<object>()),
                                                            new SimpleWhereElement(
                                                            string.Format("{0}.{1}", joinTable, joinTableId),
                                                            new List<object>())));
        }
    }
}